package com.ygxsk.carhome.ui.archive;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.ClickUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.gyf.immersionbar.ImmersionBar;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.tencent.mmkv.MMKV;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ConstantApi;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.constant.ExtraKey;
import com.ygxsk.carhome.constant.ExtraValue;
import com.ygxsk.carhome.event.EventLeadMain;
import com.ygxsk.carhome.listener.GainDataCallBackListener;
import com.ygxsk.carhome.response.ArchiveFileOutSide;
import com.ygxsk.carhome.response.ArchiveFileType;
import com.ygxsk.carhome.response.CarBrandLargeCategory;
import com.ygxsk.carhome.response.InformationManage;
import com.ygxsk.carhome.retrofit.AddLogUpLoadInfo;
import com.ygxsk.carhome.retrofit.ApiException;
import com.ygxsk.carhome.retrofit.ApiRequestSubListener;
import com.ygxsk.carhome.retrofit.ApiService;
import com.ygxsk.carhome.retrofit.ErrorConsumer;
import com.ygxsk.carhome.retrofit.NetworkManager;
import com.ygxsk.carhome.retrofit.ResponseTransformer;
import com.ygxsk.carhome.sys.Session;
import com.ygxsk.carhome.ui.ErrorActivity;
import com.ygxsk.carhome.ui.adapter.ArchiveFileItemToAdapter;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.views.ClearEditTextNoClearSK;
import com.ygxsk.carhome.views.MyLinearLayoutManager;
import com.ygxsk.integrated.retrofit.Parameterkey;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;
import butterknife.internal.DebouncingOnClickListener;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-07-27  18:17
 * @Description:档案管理主页列表【服务器端给该模块接口命名为-电子档案】
 */
public class ArchivesMainActivity extends ErrorActivity {

    //搜索框逻辑
    @BindView(R.id.et_searchincustomsmall)
    ClearEditTextNoClearSK et_searchInCustomSmall;

    //搜索文字 按钮内容
    @BindView(R.id.textviewsearchincustomsmall)
    TextView textViewSearchInCustomSmall;

    @BindView(R.id.refreshlayoutinfilearchives)
    SmartRefreshLayout refreshLayoutInFileArchives;

    @BindView(R.id.recyclerviewinfilearchives)
    RecyclerView recyclerViewInFileArchives;

    //分配客户人员
//    @BindView(R.id.roundbuttonaddgroupinrunmangroup)
//    RoundTextView roundButtonAddGroupInRunManGroup;
    //选择类型
//    @BindView(R.id.nice_spinner_type_file)
//    NiceSpinnersk nice_spinner_type_file;
//    //选择来源
//    @BindView(R.id.nice_spinner_system_file)
//    NiceSpinnersk nice_spinner_system_file;
//    //选择状态
//    @BindView(R.id.nice_spinner_state_item_file)
//    NiceSpinnersk nice_spinner_state_item_file;

    //一个临时的添加车辆品牌列表，用于携带车辆的品牌的第一条数据，
    private ArrayList<CarBrandLargeCategory> mDataResources_carBrandLarge = new ArrayList<>();
    //携带档案附件的动态管理文字过去
    private ArrayList<ArchiveFileType> mDataResources_archiveFile = new ArrayList<>();

    private ArrayList<InformationManage> mDataResources = new ArrayList<>();

    //适配器；
    private ArchiveFileItemToAdapter archiveFileItemAdapter;

    /**
     * 最后一条上传的id的信息内容
     */
    private int pagination_upLoad = Parameterkey.pageNum_default_first;

    //填充搜索的关键字
    private String keyWord_upLoad = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mActivityInstance = this;

        mSession = Session.get(this);

        //初始化筛选条件的
//        if (dataListAuthState == null) {
//            dataListAuthState = new ArrayList<>();
//        }

//        if (dataListStateItem == null) {
//            dataListStateItem = new ArrayList<>();
//        }

        initloading();

        initViews();

        gainDatas();

        //列表之内需要向外部广播数据
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }


    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_archives_main;
    }


    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();

        ImmersionBar.with(this)//
                .titleBar(R.id.toolbarygxskout)
                .fitsSystemWindows(true)//解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                //.statusBarColor(R.color.colorPrimary)//
                //.navigationBarColor(R.color.colorPrimary)//
                //.keyboardEnable(true)
                .init();

    }

    @Override
    protected void initToolBar(ToolbarHelper toolbarHelper) {

        toolbarHelper.setTitle(getString(R.string.title_file_archives));
        toolbarHelper.setVersionName(true, AppUtils.getAppVersionName());
        toolbarHelper.setLayoutClose(false, "", null);
        toolbarHelper.setLayoutLeft(true, R.drawable.backicon, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //搜索客户信息，优先关闭软键盘
                KeyboardUtils.hideSoftInput(mActivityInstance);
                methodBack();
            }
        });

//        toolbarHelper.setLayoutRight(false, 0, "", null);
        toolbarHelper.setLayoutRight(true, 1, getString(R.string.add_submit_archive), new ClickUtils.OnDebouncingClickListener() {
            @Override
            public void onDebouncingClick(View v) {

                //快速双加的限制，
                Bundle extra_bundle = new Bundle();

                // TODO: 2024/2/20 9:09  携带车辆品牌的大列表，主要为了携带一条数据；
                extra_bundle.putParcelableArrayList(ExtraKey.EXTRA_CARBRANDLARGE_DATAS, mDataResources_carBrandLarge);
                // TODO: 2024/2/21 20:00 携带动态设置的附件过去，控制底部附件的内容
                extra_bundle.putParcelableArrayList(ExtraKey.EXTRA_FILETYPES_DATAS, mDataResources_archiveFile);

                ActivityUtils.startActivity(extra_bundle, ArchiveFileAddSubmitActivity.class);

            }
        });


    }

    @Override
    protected void onClickNodata(View v) {

        gainDatas();

    }

    @Override
    protected void initViews() {

        //填充默认的hint
        if (et_searchInCustomSmall != null) {
            et_searchInCustomSmall.setHint(getString(R.string.search_keyword_car_frame));
            et_searchInCustomSmall.clearFocus();
        }

        //使用rxbinding做监听，如果1秒钟没有输入的话就自动清除焦点
//            RxTextView.afterTextChangeEvents(et_searchInCustom)
//                    .debounce(1000, TimeUnit.MILLISECONDS)//
//                    .skip(1)//过滤到第一个空字符的内容
//                    .subscribeOn(AndroidSchedulers.mainThread())//
//                    .observeOn(AndroidSchedulers.mainThread())//
//                    .subscribe(new Consumer<TextViewAfterTextChangeEvent>() {
//                        @Override
//                        public void accept(TextViewAfterTextChangeEvent textViewAfterTextChangeEvent) throws Throwable {
//
//                            //LogUtils.d(ConstantApi.LOGCAT_NOMAL + "监听到的内容是->" + textViewAfterTextChangeEvent.getView().getText().toString());
////                            if (et_searchInCustom.isFocused()) {
////                                //LogUtils.d(ConstantApi.LOGCAT_NOMAL + "afterTextChangeEvents--处于获取焦点状态");
////                                et_searchInCustom.clearFocus();//如果处于占用焦点之中，那么清理焦点
////                            }
//
//                            if (!TextUtils.isEmpty(textViewAfterTextChangeEvent.getView().getText().toString())){
//                                method_SearchSomeThing();
//                            }
//
//                        }
//                    }, new Consumer<Throwable>() {
//
//                        @Override
//                        public void accept(Throwable throwable) throws Throwable {
//                            //
//                        }
//                    });
        //软键盘的【搜索】
        et_searchInCustomSmall.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {

                if (actionId == EditorInfo.IME_ACTION_SEARCH || (keyEvent != null && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {

                    //关闭软键盘
                    KeyboardUtils.hideSoftInput(ArchivesMainActivity.this);

                    method_SearchSomeThing();

                    return true;
                }

                return false;
            }
        });

        if (textViewSearchInCustomSmall != null) {

            textViewSearchInCustomSmall.setOnClickListener(new DebouncingOnClickListener() {
                @Override
                public void doClick(View v) {

                    if (KeyboardUtils.isSoftInputVisible(ArchivesMainActivity.this)) {
                        KeyboardUtils.hideSoftInput(ArchivesMainActivity.this);
                    }

                    method_SearchSomeThing();

                }
            });
        }


        //----------------------------------------------------------------------------------------------------
        //布局的适配器填充，下拉刷新等等；
        recyclerViewInFileArchives.setLayoutManager(new MyLinearLayoutManager(this));

        //archiveFileItemAdapter = new ArchiveFileItemToAdapter(R.layout.filearchivesadapter, mDataResources);
        archiveFileItemAdapter = new ArchiveFileItemToAdapter(R.layout.archivesmainadapter, mDataResources);
        recyclerViewInFileArchives.setAdapter(archiveFileItemAdapter);
        archiveFileItemAdapter.notifyDataSetChanged();

        archiveFileItemAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {

                //档案的主页管理实体
                InformationManage informationManage = (InformationManage) adapter.getItem(position);

                if (informationManage != null) {

                    Bundle extra_bundle = new Bundle();
                    //为了携带 此档案的id,因为 EXTRA_INFORMATION_MANAGE_VO_EXTRA
                    extra_bundle.putParcelable(ExtraKey.EXTRA_INFORMATION_MANAGE, informationManage);
                    ActivityUtils.startActivity(extra_bundle, ArchiveDetailActivity.class);

                }

            }
        });

        refreshLayoutInFileArchives.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                refreshLayout.getLayout().post(new Runnable() {
                    @Override
                    public void run() {

                        pagination_upLoad = Parameterkey.pageNum_default_first;

                        //清空搜索关键字
                        keyWord_upLoad = "";
                        et_searchInCustomSmall.setText("");

                        if (mDataResources != null && !mDataResources.isEmpty()) {
                            mDataResources.clear();
                        }

                        if (archiveFileItemAdapter != null) {
                            archiveFileItemAdapter.notifyDataSetChanged();
                        }

                        getServerDatas();

                        refreshLayout.finishRefresh();

                    }
                });

            }

            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

                refreshLayout.getLayout().post(new Runnable() {
                    @Override
                    public void run() {

                        getServerDatas();

                        refreshLayout.finishLoadMore();

                    }
                });
            }
        });

    }


    private void method_SearchSomeThing() {

        //获取搜索的关键字内容,刚开始默认是空值
        keyWord_upLoad = et_searchInCustomSmall.getText().toString().trim();

        if (!TextUtils.isEmpty(keyWord_upLoad) && (keyWord_upLoad).length() < 2) {
            //ToastUtils.showShort("最少输入两个字符！");
            CommUtils.checkDialog(mAlertView);
            mAlertView = CommUtils.method_showAlertViewSingleSlowly(ArchivesMainActivity.this, ConstantSign.ALERT_TITLE, StringUtils.getString(R.string.pleaseinputkeywordtwo), true);
            mAlertView.show();
            return;
        }

        //如果发起搜索，要重置 第一页
        pagination_upLoad = Parameterkey.pageNum_default_first;

        if (mDataResources != null && !mDataResources.isEmpty()) {
            mDataResources.clear();
        }

        if (archiveFileItemAdapter != null) {
            archiveFileItemAdapter.notifyDataSetChanged();
        }

        getServerDatas();

        if (TextUtils.isEmpty(et_searchInCustomSmall.getText().toString().trim())) {
            ToastUtils.make().setGravity(Gravity.CENTER, 0, 0);
            ToastUtils.showShort(getString(R.string.pleaseinputkeyword));
        }

    }


    @Override
    protected void gainDatas() {

        //这个接口内就是刷新全部内容
        pagination_upLoad = Parameterkey.pageNum_default_first;//重置

        if (mDataResources != null && !mDataResources.isEmpty()) {
            mDataResources.clear();
        }

//        if (leadListItemAdapter != null) {
//            leadListItemAdapter.notifyDataSetChanged();
//        }

        if (NetworkUtils.isConnected()) {

            getServerDatas();

            gainCarBrandLargeCategory(null);

            //2024-2-21 19:31:03 新增 添加档案附件的 动态配置接口：
            getFileTypes();

        } else {
            //是否有其他的执行逻辑？
            netWorkError();
            setEnableLoadmore(refreshLayoutInFileArchives, false);
        }

    }

    private void getServerDatas() {

        String keyWord_upLoad = et_searchInCustomSmall.getText().toString().trim();

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());//,
        map.put(Parameterkey.clientSearch, keyWord_upLoad);//,搜索关键字
        map.put(Parameterkey.pagination, pagination_upLoad);//传递的页码
        map.put(Parameterkey.pageSize, Parameterkey.pageSize_default);//,搜索关键字

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_GETMYINFORMATIONPAGE_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.getMyInformationPage_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .getMyInformationPage(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(ArchivesMainActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<ArchiveFileOutSide>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);
                        //{"data":"","message":"无数据","code":"20002"}

                        //methodNotSuccessData(what_method, serverCode, serverMessage);

                        if (mDataResources != null && mDataResources.isEmpty()) {

                            if (refreshLayoutInFileArchives != null) {
                                refreshLayoutInFileArchives.setEnableLoadMore(false);
                            }

                            CommUtils.checkCurrently((ErrorActivity) mActivityInstance,//
                                    serverCode,//
                                    R.drawable.errorsear,//
                                    serverMessage,//
                                    getString(R.string.nulldatanow));

                        }

//                        if (serverMessage != null) {
//                            ToastUtils.showShort(serverMessage);
//                        }

                        function_response_20002(serverCode, serverMessage, addLogUpLoadInfo, false);

                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {
                        loadingGone();
                        if (refreshLayoutInFileArchives != null) {
                            refreshLayoutInFileArchives.setEnableLoadMore(true);
                        }
                    }
                }).subscribe(new Consumer<ArchiveFileOutSide>() {
                    @Override
                    public void accept(ArchiveFileOutSide archiveFileOutSide) throws Throwable {

                        if (archiveFileOutSide != null) {

                            ArrayList<InformationManage> currentDatas = archiveFileOutSide.getDataList();

                            if (currentDatas != null && !currentDatas.isEmpty()) {
                                if (mDataResources != null) {
                                    mDataResources.addAll(currentDatas);
                                }
                            }

                        }

                        //这里也不用管是下拉刷新或者上拉加载更多，直接判断是否为空，
                        if (mDataResources != null && mDataResources.isEmpty()) {
                            //同时禁用加载更多；
                            if (refreshLayoutInFileArchives != null) {
                                refreshLayoutInFileArchives.setEnableLoadMore(false);
                            }

                            fillNullDataView(StringUtils.getString(R.string.nulldatanow), R.drawable.errorsear);

                        }

                        if (archiveFileItemAdapter != null) {
                            archiveFileItemAdapter.notifyDataSetChanged();
                        }

                        //给分页值
                        pagination_upLoad = archiveFileOutSide.getNextPagination();

                        //对列表改造：
                        if (pagination_upLoad == Parameterkey.GET_NEXT_PAGINATION) {
                            setFinishLoadMoreWithNoMoreData(refreshLayoutInFileArchives, true);
                        } else {
                            setEnableLoadmore(refreshLayoutInFileArchives, true);
                        }

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {

                        //页面报错；

                    }
                });

    }

//    @Override
//    public void methodNotSuccessData(int what_method, String serverCode, String serverMessage) {
//        super.methodNotSuccessData(what_method, serverCode, serverMessage);
//
//        switch (what_method) {
//            case ConstantApi.WHAT_GETINFORMATIONMANAGELISTBYCREATEBY_URL: {
//                if (mDataResources != null && mDataResources.isEmpty()) {
//                    if (refreshLayoutInFileArchives != null) {
//                        refreshLayoutInFileArchives.setEnableLoadMore(false);
//                    }
//                    CommUtils.checkCurrently((ErrorActivity) mActivityInstance,//
//                            serverCode,//
//                            R.drawable.errorsear,//
//                            serverMessage,//
//                            getString(R.string.nulldatanow));
//                }
//                break;
//            }
//            default:
//                break;
//        }
//    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThreadInArchivesMain(EventLeadMain eventLeadMain) {

        if (eventLeadMain != null) {

            if (eventLeadMain.getMessage() == ExtraValue.EVENTBUS_EVENT_TO_REFRESH_ARCHIVES_MAIN) {

                pagination_upLoad = Parameterkey.pageNum_default_first;

                if (mDataResources != null && !mDataResources.isEmpty()) {
                    mDataResources.clear();
                }

                //一般的是由不在主页刷新，可以清理
                if (archiveFileItemAdapter != null) {
                    archiveFileItemAdapter.notifyDataSetChanged();
                }

                getServerDatas();

            }
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mDataResources_carBrandLarge != null && !mDataResources_carBrandLarge.isEmpty()) {
            mDataResources_carBrandLarge.clear();
            mDataResources_carBrandLarge = null;
        }

        if (mDataResources_archiveFile != null && !mDataResources_archiveFile.isEmpty()) {
            mDataResources_archiveFile.clear();
            mDataResources_archiveFile = null;
        }

        if (mDataResources != null && !mDataResources.isEmpty()) {
            mDataResources.clear();
        }

        if (archiveFileItemAdapter != null) {
            archiveFileItemAdapter.notifyDataSetChanged();
            archiveFileItemAdapter = null;
        }

        if (mDataResources != null) {
            mDataResources = null;
        }

        EventBus.getDefault().unregister(this);

    }

    @Override
    protected void methodBack() {
        if (ActivityUtils.isActivityAlive(this)) {
            ActivityUtils.finishActivity(this);
        }
    }

    //获取附件类型的动态配置，
    private void getFileTypes() {

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());//,

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_GETFILETYPES_URL);
        addLogUpLoadInfo.setUrlPath(ApiService.getFileTypes_url);
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_GET);
        addLogUpLoadInfo.setToastToUser(false);
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
//                .getCarBrandForVehiclePage(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
//                        MediaType.parse(ApiService.HEADER_JSON)))
                .getFileTypes()
                .compose(ArchivesMainActivity.this.bindUntilEvent(ActivityEvent.DESTROY))
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<ArrayList<ArchiveFileType>>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        //这里不能给提示的。是一个后台运行的接口,预加载数据

                    }
                })).subscribe(new Consumer<ArrayList<ArchiveFileType>>() {
                    @Override
                    public void accept(ArrayList<ArchiveFileType> archiveFileTypeArrayList) throws Throwable {

                        if (mDataResources_archiveFile != null && !mDataResources_archiveFile.isEmpty()) {
                            mDataResources_archiveFile.clear();
                        }

                        if (archiveFileTypeArrayList != null && !archiveFileTypeArrayList.isEmpty()) {

                            if (mDataResources_archiveFile != null) {
                                mDataResources_archiveFile.addAll(archiveFileTypeArrayList);
                            }

                            String jsonString = JSON.toJSONString(archiveFileTypeArrayList);

                            //存入本地主要是为了在详情之中取出
                            MMKV.defaultMMKV().encode(ConstantSign.MMKV_KEY_FILE_TYPE_LIST, jsonString);

                        } else {
                            //清空这个存储值内容
                            MMKV.defaultMMKV().encode(ConstantSign.MMKV_KEY_FILE_TYPE_LIST, "");
                        }

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {
                        function_apiException(apiException);
                    }
                });

    }

    //获取车辆的品牌--大范畴-此处添加的是【新车的】车辆品牌；
    private void gainCarBrandLargeCategory(GainDataCallBackListener _gainDataCallBackListener) {

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());//,

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_GETCARBRANDFORVEHICLEPAGE);
        addLogUpLoadInfo.setUrlPath(ApiService.getCarBrandForVehiclePage_url);
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);
        addLogUpLoadInfo.setToastToUser(true);
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .getCarBrandForVehiclePage(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(ArchivesMainActivity.this.bindUntilEvent(ActivityEvent.DESTROY))
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<ArrayList<CarBrandLargeCategory>>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);
                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

                        //清理车辆品牌数据库内容,暂时不清空，仅仅只是携带第一条或者整列数据
//                        CarBrandLargeCategoryDaoManager.getInstance().deleteAllCarBrand();
//                        method_create_materialDialog(mActivityInstance, ConstantSign.TIPS_LOADING);

                    }
                }).subscribe(new Consumer<ArrayList<CarBrandLargeCategory>>() {
                    @Override
                    public void accept(ArrayList<CarBrandLargeCategory> carBrandLargeCategories) throws Throwable {

                        if (mDataResources_carBrandLarge != null && !mDataResources_carBrandLarge.isEmpty()) {
                            mDataResources_carBrandLarge.clear();
                        }

                        if (carBrandLargeCategories != null && !carBrandLargeCategories.isEmpty()) {

                            if (mDataResources_carBrandLarge != null) {

                                mDataResources_carBrandLarge.addAll(carBrandLargeCategories);

                                //先排序 2024年1月26日10:51:26我去掉了排序，因为后台给的数据排在前边的大多是有车系的。
//                                CommUtils.CollectionsSort_CarBrandLargeCategory_CHINA(mDataResources_carBrandLarge);
                                //填充车辆品牌的数据
//                                CarBrandLargeCategoryDaoManager.getInstance().insertMultCarBrand(mDataResources_carBrandLarge);


                            }

                        }

//                        CommUtils.checkMaterialDialog(materialDialog);

//                        if (_gainDataCallBackListener != null) {
//                            _gainDataCallBackListener.doSomeThing();
//                        }

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {
//                        CommUtils.checkMaterialDialog(materialDialog);
                    }
                });

    }

}